package main;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * The Manuscript class is a representation of a single
 * manuscript document that contains its name, author
 * and list of reviews.
 * 
 * Cris added serializable and added methods
 * Holly changed my_author_id type from int to String 11/21
 * Holly added my_reviewers array list along with methods relating to reviewers
 * 
 * @author Daniel Anderson
 * @version 12/3
 */
public class Manuscript implements Serializable{
	
	/**
	 * Generated serial version UID
	 */
	private static final long serialVersionUID = 9192353501010626121L;

	private Status my_status;
	private String my_title;
	private String my_author;
	private String my_author_id;
	private String my_text;
	private ArrayList<Review> my_reviews;
	private ArrayList<String> my_reviewers;
	
	/**
	 * Default Constructor
	 * Holly added my_reviewers initialization 12/1
	 */
	public Manuscript() {
		my_status = Status.UNDECIDED;
		my_title = "Default_Title";
		my_author = "Default_Author";
		my_author_id = "-1";
		my_text = "default";
		my_reviews = new ArrayList<Review>();
		my_reviewers = new ArrayList<String>();
	}//end of constructor1
	
	/**
	 * Second constructor for creating custom Manuscripts.
	 * Holly changed the_id to a String type 11/21
	 * Holly added my_reviers initialization 12/1
	 * @param the_title Title of the paper.
	 * @param the_author Full name of the author.
	 * @param the_id Author's user ID.
	 * @param the_text The manuscript text.
	 */
	public Manuscript(String the_title, String the_author, String the_id, String the_text) {
		my_status = Status.UNDECIDED;
		my_title = the_title;
		my_author = the_author;
		my_author_id = the_id;
		my_text = the_text;
		my_reviews = new ArrayList<Review>();
		my_reviewers = new ArrayList<String>();
	}//end of constructor2
	
	//------------------------------//
	//----------Accessors-----------//
	//------------------------------//
	
	/**
	 * @return The title of the paper
	 */
	public String getTitle() {
		return my_title;
	}//end of getTitle
	
	/**
	 * @return The author's full name
	 */
	public String getAuthor() {
		return my_author;
	}//end of getAuthor
	
	/**
	 * @return The author's unique ID
	 */
	public String getAuthorID() {
		return my_author_id;
	}//end of getAuthorID
	
	/**
	 * @return Text of the manuscript.
	 */
	public String getText() {
		return my_text;
	}//end of getText
	
	/**
	 * @return ArrayList of reviews.
	 */
	public ArrayList<Review> getReviews()
	{
		return my_reviews;
	}//end of getReviews
	
	/**
	 * @return The number of reviews
	 */
	public int getNumReviews() {
		return my_reviews.size();
	}//end getNumReviews
	
	/**
	 * @return The status of the manuscript
	 */
	public Status getStatus(){
		return my_status;
	}//end getStatus
	
	/**
	 * @return the list of reviewers for manuscript
	 */
	public ArrayList<String> getReviewers(){
		return my_reviewers;
	}
	
	//------------------------------//
	//-----------Mutators-----------//
	//------------------------------//
	
	/**
	 * @param the_status The new status
	 */
	public void setStatus(Status the_status) {
		my_status = the_status;
	}//end setStatus
	
	/**
	 * @author Holly Beach
	 * Preconditions: user_id != getAuthorID();
	 * 				getReviewers.contains(user_id) == false
	 * Postconditions: getReviewers.size() 
	 * 				getReviewers.contains(user_id) == true
	 */
	public void addReviewer(String user_id) {
		my_reviewers.add(user_id);
	}
	
	/**
	 * @param the_review The new review to be added.
	 */
	public void addReview(Review the_review) {
		my_reviews.add(the_review);
	}//end addReview
	
	/**
	 * Updates a review by replacing it with a new one.
	 * @param the_original_review The old review.
	 * @param the_new_review The new review.
	 */
	public void updateReview(Review the_original_review, Review the_new_review) {
		my_reviews.set(my_reviews.indexOf(the_original_review), the_new_review);
	}//end updateReview
	
	/**
	 * Removes a specified review from the manuscript.
	 * @param the_review The review to be removed.
	 */
	public void removeReview(Review the_review) {
		my_reviews.remove(the_review);
	}//end removeReview
	
	/**
	 * Checks if the passed object is equal
	 * 
	 * @author Cristopher
	 * 
	 * Precondition: the object passed in is a manuscript
	 */
	public boolean equals(Object the_obj) {
		Manuscript passed = (Manuscript)the_obj;
		return (passed.my_author_id.equals(my_author_id))&&
				(passed.getTitle().equals(my_title));
	}
	
	/**
	 * Sets the manuscript text
	 * 
	 * @author Cristopher
	 * @param the_text
	 */
	public void setText(String the_text) {
		my_text = the_text;
	}
}//end of Manuscript